package com.foreknow.dao.Impl;

import com.foreknow.dao.AdminDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;
import com.foreknow.model.Admin;

import java.sql.SQLException;
import java.util.List;

public class AdminDaoImpl extends BaseDAO implements AdminDao {
    @Override
    public boolean save(Admin admin) throws SQLException {
        String sql="insert into admin(adminName,password) values(?,?)";
        int update = jdbcTemplate.update(sql, admin.getAdminName(), admin.getPassword());
        return update==1;
    }

    @Override
    public Admin queryAll(String name,String password) throws SQLException {
        String sql="select * from admin where adminName=? and password=?";
        EntityMapping mapping = mappingFactory.getmap(MappingFactory.ADMINMAPPING);
        List<Object> list = jdbcTemplate.query(sql, mapping,name,password);
        if (list.size()>0){
            Admin admin= (Admin) list.get(0);
            return admin;
        }
        return null;
    }
}
